package com.xiaoxin.common;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @version v1.0
 * @Description: MybatisPlus 配置
 * @Author: TongRui乀
 * @Date: 2021/11/22 6:30 下午
 */
@Configuration
public class MybatisPlusConfig {

    /**
     * @Description: 配置分页插件
     * @throws
     * @date 2021/11/22 6:32 下午
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    @Bean
    public IdentifierGenerator myDefaultIdentifierGenerator() throws UnknownHostException {
        return new MyIdentifierGenerator(InetAddress.getLocalHost());
    }


}
